package com.dms.modules.cart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dms.modules.cart.entity.CartItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface CartMapper extends BaseMapper<CartItem> {
    
    /**
     * 更新购物车项选中状态
     * @param userId 用户ID
     * @param selected 选中状态
     * @return 受影响行数
     */
    @Update("UPDATE cart SET selected = #{selected} WHERE user_id = #{userId} AND deleted = 0")
    int updateCartSelectedStatus(@Param("userId") Long userId, @Param("selected") Integer selected);
    
    /**
     * 更新购物车商品数量
     * @param id 购物车ID
     * @param quantity 数量
     * @param totalPrice 总价
     * @return 受影响行数
     */
    @Update("UPDATE cart SET quantity = #{quantity}, total_price = #{totalPrice} WHERE id = #{id} AND deleted = 0")
    int updateCartItemQuantity(@Param("id") Long id, @Param("quantity") Integer quantity, @Param("totalPrice") java.math.BigDecimal totalPrice);
    
    /**
     * 清空购物车
     * @param userId 用户ID
     * @return 受影响行数
     */
    @Update("UPDATE cart SET deleted = 1 WHERE user_id = #{userId}")
    int clearCart(@Param("userId") Long userId);
} 